<!--实施监控-->
<template>
  <div class="monitorConatiner">
    <van-sticky>
      <!--头部bar开始-->
      <CommonBar :options="options"></CommonBar>
      <!--头部bar结束-->
    </van-sticky>
    <!--选行政区开始-->
    <!--上面筛选统计开始-->
    <div v-show="isopencx">
      <p class="bottomcount bottomradius bottomcountfix" @click="topela" v-show="toptitleshow">查询</p>
      <div class="searchdiv fadeleftdown" v-show="topellipsis">
        <div class="areacontent">
          <van-row gutter="30">
            <!--项目公司1-->
            <van-col span="12" v-show="projectcompanydisplay">
              <van-dropdown-menu active-color="#0AD691">
                <van-dropdown-item
                  v-model="ProjectCompany"
                  :options="ProjectCompanycolumns"
                  @change="onConfirmProjectCompany"
                />
              </van-dropdown-menu>
            </van-col>
            <!--项目部13-->
            <van-col span="12" v-show="projectdisplay">
              <van-dropdown-menu active-color="#0AD691">
                <van-dropdown-item
                  v-model="Project"
                  :options="Projectcolumns"
                  @change="onConfirmProject"
                />
              </van-dropdown-menu>
            </van-col>
            <!--项目公司停车场1-->
            <van-col span="12" v-show="projectcompanyparkdisplay">
              <van-dropdown-menu active-color="#0AD691">
                <van-dropdown-item
                  v-model="ProjectCompanyPark"
                  :options="ProjectCompanyParkcolumns"
                  @change="onConfirmProjectCompanyPark"
                />
              </van-dropdown-menu>
            </van-col>
            <!--项目公司回收站1-->
            <van-col span="12" v-show="projectcompanydumpdisplay">
              <van-dropdown-menu active-color="#0AD691">
                <van-dropdown-item
                  v-model="ProjectCompanyDump"
                  :options="ProjectCompanyDumpcolumns"
                  @change="onConfirmProjectCompanyDump"
                />
              </van-dropdown-menu>
            </van-col>

            <!--项目部垃圾桶13-->
            <van-col span="12" v-show="projecttrashdisplay">
              <van-dropdown-menu active-color="#0AD691">
                <van-dropdown-item
                  v-model="ProjectTrash"
                  :options="ProjectTrashcolumns"
                  @change="onConfirmProjectTrash"
                />
              </van-dropdown-menu>
            </van-col>
            <!--项目部车辆13-->
            <van-col span="12" v-show="projectcardisplay">
              <van-dropdown-menu active-color="#0AD691">
                <van-dropdown-item
                  v-model="ProjectCar"
                  :options="ProjectCarcolumns"
                  @change="onConfirmProjectCar"
                />
              </van-dropdown-menu>
            </van-col>
            <!--项目片区135-->
            <van-col span="12" v-show="dirstdisplay">
              <van-dropdown-menu active-color="#0AD691">
                <van-dropdown-item
                  v-model="District"
                  :options="Districtcolumns"
                  @change="onConfirmDistrict"
                />
              </van-dropdown-menu>
            </van-col>
            <!--项目责任区1356-->
            <van-col span="12" v-show="dutydisplay">
              <van-dropdown-menu active-color="#0AD691">
                <van-dropdown-item
                  v-model="DutyArea"
                  :options="DutyAreacolumns"
                  @change="onConfirmDutyArea"
                />
              </van-dropdown-menu>
            </van-col>
          </van-row>
        </div>
        <p class="bottomcount bottomradius" @click="topelatitle">查询</p>
      </div>
    </div>
    <!--选行政区结束-->
    <!--地图开始-->
    <div id="bmap" class="bm-view"></div>
    <!--地图结束-->
    <!--左侧边统计开始-->
    <p class="sidecounticom sidecounticomshow" @click="ela" v-show="titleshow">查看统计数据</p>
    <div class="sidecount fadeleftIn" v-show="ellipsis">
      <ul class="sidecount_ul">
        <li class="sidecount_li">
          <div class="sideflex">
            <van-image :src="prople" class="sideicon" width="38" />
            <div class="sideflexright">
              <p class="sidetext">{{leftsideList.work_number}}</p>
              <p class="title">到岗人数</p>
            </div>
          </div>
        </li>

        <li class="sidecount_li">
          <div class="sideflex">
            <van-image :src="prople" class="sideicon" width="38" />
            <div class="sideflexright">
              <p class="sidetext">{{leftsideList.nowork_number}}</p>
              <p class="title">未到岗人数</p>
            </div>
          </div>
        </li>
        <li class="sidecount_li">
          <div class="sideflex">
            <van-image :src="prople" class="sideicon" width="38" />
            <div class="sideflexright">
              <p class="sidetext">{{(leftsideList.work_rate*100).toFixed(2)}}%</p>
              <p class="title">人员到岗率(%)</p>
            </div>
          </div>
        </li>
        <li class="sidecount_li">
          <div class="sideflex">
            <van-image :src="car" class="sideicon" width="38" />
            <div class="sideflexright">
              <p class="sidetext">{{leftsideList.shipping_number}}</p>
              <p class="title">垃圾收运数(吨)</p>
            </div>
          </div>
        </li>
        <li class="sidecount_li">
          <div class="sideflex">
            <van-image :src="car" class="sideicon" width="38" />
            <div class="sideflexright">
              <p class="sidetext">{{leftsideList.clean_area}}</p>
              <p class="title">清扫面积(平米)</p>
            </div>
          </div>
        </li>
        <li class="sidecount_li">
          <div class="sideflex">
            <van-image :src="car" class="sideicon" width="38" />
            <div class="sideflexright">
              <p class="sidetext">{{leftsideList.workcar_number}}</p>
              <p class="title">车辆到岗数</p>
            </div>
          </div>
        </li>
      </ul>
      <p class="sidecounticom" @click="elatitle">查看统计数据</p>
    </div>
    <!--左侧边统计结束-->
    <!--右侧边统计开始-->
    <div v-show="isopentc">
      <p
        class="sidecounticom sidecountirightradius sidecountirightshow"
        @click="tuceng"
        v-show="tctitleshow"
      >查看图层控制</p>
      <div class="sidecountright fadeleftOut" v-show="tcellipsis">
        <p class="sidecounticom sidecountirightshow" @click="tcelatitle">查看图层控制</p>
        <ul class="sidecountright_ul">
          <li class="sidecountright_li title">图层控制</li>
          <li class="sidecountright_li" @click="showOrHide('company','overlay')">
            <van-icon name="success" class="successicon" v-if="successiconshow" />
            <van-icon v-else class="successicon" />
            <span>项目公司围栏</span>
            <span class="labelcircle company"></span>
          </li>

          <li class="sidecountright_li" @click="showOrHide('project','overlay')">
            <van-icon name="success" class="successicon" v-if="successiconshow1" />
            <van-icon v-else class="successicon" />
            <span>项目部围栏</span>
            <span class="labelcircle project"></span>
          </li>
          <li class="sidecountright_li" @click="showOrHide('district','overlay')">
            <van-icon name="success" class="successicon" v-if="successiconshow2" />
            <van-icon v-else class="successicon" />
            <span>项目片区围栏</span>
            <span class="labelcircle district"></span>
          </li>
          <li class="sidecountright_li" @click="showOrHide('user','overlay')">
            <van-icon name="success" class="successicon" v-if="successiconshow3" />
            <van-icon v-else class="successicon" />
            <span>责任区围栏</span>
            <span class="labelcircle user"></span>
          </li>

          <li class="sidecountright_li" @click="showOrHide('car','overlay')">
            <van-icon name="success" class="successicon" v-if="successiconshow9" />
            <van-icon v-else class="successicon" />
            <span>车辆围栏</span>
            <span class="labelcircle car"></span>
          </li>
          <li class="sidecountright_li" @click="showOrHide('park','overlay')">
            <van-icon name="success" class="successicon" v-if="successiconshow6" />
            <van-icon v-else class="successicon" />
            <span>停车场围栏</span>
            <span class="labelcircle park"></span>
          </li>
          <li class="sidecountright_li" @click="showOrHide('dump','overlay')">
            <van-icon name="success" class="successicon" v-if="successiconshow7" />
            <van-icon v-else class="successicon" />
            <span>回收站围栏</span>
            <span class="labelcircle dump"></span>
          </li>
          <li class="sidecountright_li" @click="showOrHideCarAndUser('user','marker')">
            <van-icon name="success" class="successicon" v-if="successiconshow4" />
            <van-icon v-else class="successicon" />
            <span>保洁员</span>
          </li>
          <li class="sidecountright_li" @click="showOrHideCarAndUser('car','marker')">
            <van-icon name="success" class="successicon" v-if="successiconshow5" />
            <van-icon v-else class="successicon" />
            <span>车辆</span>
          </li>
          <li class="sidecountright_li" @click="showOrHideCarAndUser('trash','marker')">
            <van-icon name="success" class="successicon" v-if="successiconshow8" />
            <van-icon v-else class="successicon" />
            <span>垃圾桶</span>
          </li>
        </ul>
      </div>
    </div>
    <!--右侧边统计结束-->

    <!--表格开始-->
    <p class="bottomcount bottomfix" @click="bgeal" v-show="bgtitleshow">查看实时报警</p>
    <div class="contebt fadeleftup" v-show="bgellipsis1">
      <p class="bottomcount" @click="bgtitle">查看实时报警</p>
      <ul class="contebt_ul">
        <li class="contebt_li countScoreHeader">
          <span class="span1">时间</span>
          <span class="span2">项目部</span>
          <span class="span3">对象</span>
          <span class="span4">事件</span>
          <span class="span5">事件信息</span>
        </li>
        <ul class="uldemo">
          <li class="contebt_li" v-for="(item, index) in alertData" :key="index">
            <span class="span1">{{item.create_date}}</span>
            <span class="span2">{{item.project_name}}</span>
            <span class="span3">{{item.plate_number}}</span>
            <span class="span4 color1" v-if="item.type==1">位置报警</span>
            <span class="span4 color2" v-if="item.type==2">上下线报警</span>
            <span class="span4 color3" v-if="item.type==3">超速报警</span>
            <span class="span4 color4" v-if="item.type==4">偏离路线</span>
            <span class="span5">{{item.address_T}}</span>
          </li>
        </ul>
      </ul>
    </div>

    <!--表格结束-->
  </div>
</template>

<script>
import { BmlLushu, BmlMarkerClusterer } from "vue-baidu-map";
import { mapState } from "vuex";
import CommonBar from "../common/commonBar";
import BMap from "BMap";
import { parse } from "path";
export default {
  components: {
    CommonBar,
    BmlLushu,
    BmlMarkerClusterer
  },

  computed: {
    ...mapState({
      token: state => state.Authorization,
      user_department_type: state => state.userData.department_type, //人员类型
      user_department_id: state => state.userData.department_id, // 人员id
      user_id: state => state.userData.id
    })
  },
  data() {
    return {
      // user_department_type: "6",
      // user_department_id: "4",
      isopencx: true,
      //展示收缩
      arrow: "<<",
      prople: require("../../../static/image/monitor_two.png"),
      car: require("../../../static/image/monitor_one.png"),
      scount: require("../../../static/image/monitor_fore.png"),
      trashcar: require("../../../static/image/monitor_three.png"),
      sapdi: require("../../../static/image/monitor_five.png"),
      titleshow: true,
      tctitleshow: true,
      toptitleshow: true,
      bgtitleshow: true,
      ellipsis: false,
      tcellipsis: false,
      bgellipsis1: false,
      topellipsis: false,
      //公共bar
      options: {
        type: "icon",
        centerText: "实时监控",
        iconNname: "wap-home",
        lefttype: "left"
      },
      projectcompanydisplay: true,
      projectcompanyparkdisplay: true,
      projectcompanydumpdisplay: true,
      projectdisplay: true,
      projecttrashdisplay: true,
      projectcardisplay: true,
      dirstdisplay: true,
      dutydisplay: true,
      //项目公司
      ProjectCompany: 0,
      ProjectCompanycolumns: [{ text: "选择项目公司", value: 0 }],
      //项目部
      Project: 0,
      Projectcolumns: [{ text: "选择项目部", value: 0 }],
      //片区
      District: 0,
      Districtcolumns: [{ text: "选择项目片区", value: 0 }],
      //责任区
      DutyArea: 0,
      DutyAreacolumns: [{ text: "选择责任区", value: 0 }],
      //项目公司停车场
      ProjectCompanyPark: 0,
      ProjectCompanyParkcolumns: [{ text: "选择停车场", value: 0 }],
      //项目公司回收站
      ProjectCompanyDump: 0,
      ProjectCompanyDumpcolumns: [{ text: "选择回收站", value: 0 }],
      //项目部垃圾桶
      ProjectTrash: 0,
      ProjectTrashcolumns: [{ text: "选择垃圾桶", value: 0 }],
      //项目部车辆
      ProjectCar: 0,
      ProjectCarcolumns: [{ text: "选择车辆", value: 0 }],
      //报警信息表格
      messageList: [],
      pageSize: 5,
      pageNumber: 1,

      //项目公司

      polygonPathcompany: [],
      //项目部
      polygonPathproject: [],
      //片区
      polygonPathdistict: [],
      //责任区
      polygonPathduty: [],
      //地图
      bmap: null,
      company_info: [], // 存放项目公司信息
      project_info: [], // 存放项目部信息
      district_info: [], // 存放片区信息
      user_info: [], // 存放保洁员信息
      car_info: [], // 存放车辆信息
      park_info: [], // 存放停车场信息
      dump_info: [], // 存放垃圾回收站信息
      trash_info: [], // 存放垃圾桶信息
      manager_info: [], // 存放片区管理员信息
      //参数赋值
      group_department_id: "",
      project_company_id: "",
      project_id: "",
      district_id: "",
      duty_id: "",
      /**图层控制 */
      successiconshow: true,
      successiconshow2: true,
      successiconshow3: true,
      successiconshow1: true,
      successiconshow4: true,
      successiconshow5: true,
      successiconshow6: true,
      successiconshow7: true,
      successiconshow8: true,
      successiconshow9: true,
      isopentc: true,
      //socket
      websocketURL: "ws://222.88.248.111:5898",
      websocket_person: null,
      // websocket_car: null,
      websocket_person_status: false,
      websocket_car_status: false,
      websocket_manager_status: false,
      alertData: [],
      leftsideList: {},
      icon_map: {
        user: {
          1: require("../../../static/image/mapuser.png"),
          2: require("../../../static/image/user_online.png")
        },
        manager: {
          1: require("../../../static/image/manager_online.png"),
          2: require("../../../static/image/manager-offline.png")
        },
        car: {
          1: require("../../../static/image/car-online.png"),
          2: require("../../../static/image/car-offline.png")
        },
        trash: require("../../../static/image/maptrash.png")
      }
      // icon_map: {
      //   user: require("../../../static/image/mapuser.png"),
      //   car: require("../../../static/image/car-online"),
      //   trash: require("../../../static/image/maptrash.png"),
      //   manager: require("../../../static/image/mapmange.png")
      // }
    };
  },
  mounted() {
    console.log(typeof this.car_info);

    //  this.connectWebsocket()
    //this.initWebSocket();
    this.initBmap();
    // this.initFirst();

    if (this.user_department_type == 1 || this.user_department_type == 7) {
      //集团管理员一类
      this.getCompanys();
      this.projectcardisplay = false;
      this.projecttrashdisplay = false;
      this.dirstdisplay = false;
      this.dutydisplay = false;
    } else if (this.user_department_type == 3) {
      //项目公司一类 不能选项目公司
      this.getCompanys();
      this.projectcompanydisplay = false;
      this.projectcardisplay = false;
      this.projecttrashdisplay = false;
      this.dirstdisplay = false;
      this.dutydisplay = false;
      // this.getProjects();
      // this.getParks();
      // this.getDumps();
    } else if (this.user_department_type == 5) {
      //项目部一类 不能选项目部和停车场和回收站
      this.projectcompanydisplay = false;
      this.projectcompanyparkdisplay = false;
      this.projectcompanydumpdisplay = false;
      this.projectdisplay = false;
      this.getProjects();
      // this.getCars();
      // this.getDistricts();
    } else if (this.user_department_type == 6) {
      //片区管理员 不能选项目部和停车场和回收站 片区
      this.projectcompanydisplay = false;
      this.projectcompanyparkdisplay = false;
      this.projectcompanydumpdisplay = false;
      this.projectdisplay = false;
      this.projectcardisplay = false;
      this.projecttrashdisplay = false;
      this.dirstdisplay = false;
      this.getDistricts();
      // this.getUsers();
    } else {
      this.$toast({ message: "抱歉，此页面功能不对您开放" });
    }

    // this.checkOnline();
    // this.timeinter1 = setInterval(this.checkOnline, 60000);
    //统计信息
    this.getStatisticInfo();
    this.timeinter = setInterval(this.getStatisticInfo, 1800000); //1800000隔半个小时发一次
  },
  created() {
    var sele = this;
    window.viewGps = sele.viewGps;
  },
  methods: {
    /**socket操作 */
    // 链接websocket
    /* * 初始化websocket
     */
    //车
    carwebsocket() {
      var serviceIp = "222.88.248.111:5898";
      let that = this;
      let ws = new WebSocket("ws://" + serviceIp + "?token=" + this.token);
      this.interval = window.setInterval(function() {
        //每隔30秒钟发送一次心跳，避免websocket连接因超时而自动断开
        if (ws != null) {
          ws.send('{"type":"pong"}');
        }
      }, 179000);

      ws.onopen = () => {
        // Web Socket 已连接上，使用 send() 方法发送数据
        //ws.send("car");
        console.log("数据发送中...");
      };
      ws.onmessage = event => {
        var data = event.data;
        if (typeof data == "string") {
          data = eval("(" + data + ")");
        }

        if (data.ret == 200) {
          // console.log("接收到的消息", event);
          if (!this.websocket_car_status) {
            this.websocket_car_status = true;
            let sim_no = "";
            var car_info = that.car_info;
            for (let i in car_info) {
              if (car_info[i].simNo && car_info[i].simNo != "") {
                sim_no += car_info[i].simNo;
                sim_no += ",";
              }
            }
            sim_no = sim_no.substring(0, sim_no.length - 1);
            var msg = {
              sim_no: sim_no,
              get_message_type: "car",
              token: that.token,
              USER_ID: that.user_id,
              type: "auth"
            };
            console.info("car", msg);
            msg = JSON.stringify(msg);
            ws.send(msg);
            //that.send(msg);
          }
        } else {
          //console.info("car",data)
          if (data.coordinates.simNo && data.coordinates.simNo != "") {
            //console.info("car coordinates", data.coordinates);
            let coordinates = data.coordinates;
            var car_info = that.car_info;
            for (let j in car_info) {
              if (coordinates.simNo == car_info[j].simNo) {
                car_info[j].coordinates = {
                  lng: coordinates.longitude,
                  lat: coordinates.latitude,
                  direction: coordinates.direction,
                  mileage: coordinates.mileage,
                  velocity: coordinates.velocity
                };
                that.showAndSaveMarker(car_info[j], "car");
                break;
              }
            }
          } else if (data.alert.car_id && data.alert.car_id != "") {
            var position = JSON.parse(data.alert.position);
            var myGeo = new BMap.Geocoder({ extensions_town: true });
            // 根据坐标得到地址描述
            myGeo.getLocation(
              new BMap.Point(position.lng, position.lat),
              function(result) {
                if (result) {
                  data.alert.address_T = result.address;
                }
                that.alertData = that.alertData.concat(data.alert);
                console.log("报警数组", that.alertData);
                that.alertData.sort(function(a, b) {
                  return Date.parse(b.create_date) - Date.parse(a.create_date); //时间正序
                });
                if (that.alertData.length > 5) {
                  that.alertData.pop();
                }
              }
            );

            // that.alertData = that.alertData.concat(data.alert);
            // console.log("报警数组", that.alertData);
            // that.alertData.sort(function(a, b) {
            //   return Date.parse(b.create_date) - Date.parse(a.create_date); //时间正序
            // });
            // if (that.alertData.length > 5) {
            //   that.alertData.pop();
            // }
          }
        }
      };
      ws.onerror = function() {
        console.log("WebSocket连接发生错误");
      };
      ws.onclose = function() {
        // 关闭 websocket
        console.log("车连接已关闭...");
        setTimeout(() => {
          that.websocket_car = null;
          that.websocket_car_status = false;
          that.carwebsocket();
        }, 2000);
      };

      // 路由跳转时结束websocket链接
      // 路由跳转时结束websocket链接
      this.$router.afterEach(function() {
        ws.send('{"type":"Maintenance"}');
        window.clearInterval(that.interval);
      });
    },
    //ren
    personwebsocket() {
      var serviceIp = "222.88.248.111:5898";
      let that = this;
      let ws = new WebSocket("ws://" + serviceIp + "?token=" + this.token);
      this.interval1 = window.setInterval(function() {
        //每隔30秒钟发送一次心跳，避免websocket连接因超时而自动断开
        if (ws != null) {
          ws.send('{"type":"pong"}');
        }
      }, 179000);
      ws.onopen = () => {
        // Web Socket 已连接上，使用 send() 方法发送数据
        // ws.send("person");
        console.log("数据发送中...");
      };
      ws.onmessage = msg => {
        // console.log('数据已接收...')
        if (typeof msg == "string") {
          msg = JSON.parse(msg);
        }
        var data = msg.data;
        if (typeof data == "string") {
          data = JSON.parse(data);
        }
        if (data.ret == 200) {
          if (!this.websocket_person_status) {
            this.websocket_person_status = true;
            let sim_no = "";
            var user_info = that.user_info;
            for (let i in user_info) {
              if (user_info[i].imei && user_info[i].imei != "") {
                sim_no += user_info[i].imei;
                sim_no += ",";
              }
            }
            sim_no = sim_no.substring(0, sim_no.length - 1);
            var msg = {
              sim_no: sim_no,
              get_message_type: "user",
              token: that.token,
              USER_ID: that.user_id,
              type: "auth"
            };
            console.info("user send msg", msg);
            msg = JSON.stringify(msg);
            ws.send(msg);
          }
        } else {
          //console.info("user",data)
          if (data.coordinates.imei && data.coordinates.imei != "") {
            let coordinates = data.coordinates;
            var user_info = that.user_info;
            for (let j in user_info) {
              if (coordinates.simNo == user_info[j].imei) {
                user_info[j].coordinates = {
                  lng: coordinates.longitude,
                  lat: coordinates.latitude
                };
                user_info[j].batV = coordinates.batV;
                user_info[j].csq = coordinates.csq;
                user_info[j].is_online = 1;
                user_info[j].updateTime = coordinates.deviceTime;
                console.info(user_info[j]);
                that.showAndSaveMarker(user_info[j], "user");
                break;
              }
            }
          } else if (data.alert.id && data.alert.id != "") {
            console.log("人员报警");
            // var position = JSON.parse(data.alert.position);
            // var myGeo = new BMap.Geocoder({ extensions_town: true });
            // // 根据坐标得到地址描述
            // myGeo.getLocation(
            //   new BMap.Point(position.lng, position.lat),
            //   function(result) {
            //     if (result) {
            //       data.alert.address_T = result.address;
            //     }
            //     that.alertData = that.alertData.concat(data.alert);
            //     console.log("报警数组", that.alertData);
            //     that.alertData.sort(function(a, b) {
            //       return Date.parse(b.create_date) - Date.parse(a.create_date); //时间正序
            //     });
            //     if (that.alertData.length > 5) {
            //       that.alertData.pop();
            //     }
            //   }
            // );
          }
        }
      };
      ws.onerror = function() {
        console.log("WebSocket连接发生错误");
      };
      ws.onclose = function() {
        // 关闭 websocket
        console.log("人连接已关闭...");
        setTimeout(() => {
          that.websocket_person = null;
          that.websocket_person_status = false;
          that.personwebsocket();
        }, 2000);
      };

      // 路由跳转时结束websocket链接
      this.$router.afterEach(function() {
        ws.send('{"type":"Maintenance"}');
        window.clearInterval(that.interval1);
      });
    },
    //管理员
    managerwebsocket() {
      var serviceIp = "222.88.248.111:5898";
      let that = this;
      let ws = new WebSocket("ws://" + serviceIp + "?token=" + this.token);
      this.interval2 = window.setInterval(function() {
        //每隔30秒钟发送一次心跳，避免websocket连接因超时而自动断开
        if (ws != null) {
          ws.send('{"type":"pong"}');
        }
      }, 179000);
      ws.onopen = () => {
        // Web Socket 已连接上，使用 send() 方法发送数据
        // ws.send("person");
        console.log("管理员数据发送中...");
      };
      ws.onmessage = msg => {
        // console.log('数据已接收...')
        if (typeof msg == "string") {
          msg = JSON.parse(msg);
        }
        var data = msg.data;
        if (typeof data == "string") {
          data = JSON.parse(data);
        }
        if (data.ret == 200) {
          if (!this.websocket_manager_status) {
            this.websocket_manager_status = true;
            let sim_no = "";
            var user_info = that.user_info;
            for (let i in user_info) {
              if (user_info[i].is_leader == "1") {
                sim_no += user_info[i].id;
                sim_no += ",";
              }
            }
            sim_no = sim_no.substring(0, sim_no.length - 1);
            var msg = {
              sim_no: sim_no,
              get_message_type: "system",
              token: that.token,
              USER_ID: that.user_id,
              type: "auth"
            };
            console.info("manager send msg", msg);
            msg = JSON.stringify(msg);
            ws.send(msg);
          }
        } else {
          if (typeof data.system == "string") {
            data.system = JSON.parse(data.system);
          }
          if (data.system.imei && data.system.imei != "") {
            let coordinates = data.system;
            var user_info = that.user_info;
            for (let j in user_info) {
              if (coordinates[user_info[j].id]) {
                user_info[j].coordinates = {
                  lng: coordinates[user_info[j].id].longitude,
                  lat: coordinates[user_info[j].id].latitude
                };
                user_info[j].batV = coordinates.batV;
                user_info[j].csq = coordinates.csq;
                user_info[j].is_online = 1;
                user_info[j].updateTime = coordinates.deviceTime;
                console.info(user_info[j]);
                console.log(user_info[j]);
                that.showAndSaveMarker(user_info[j], "manager");
                break;
              }
            }
          }
        }
      };
      ws.onerror = function() {
        console.log("WebSocket连接发生错误");
      };
      ws.onclose = function() {
        // 关闭 websocket
        console.log("管理员连接已关闭...");
        setTimeout(() => {
          that.websocket_manager = null;
          that.websocket_manager_status = false;
          that.managerwebsocket();
        }, 2000);
      };

      // 路由跳转时结束websocket链接
      this.$router.afterEach(function() {
        ws.send('{"type":"Maintenance"}');
        window.clearInterval(that.interval2);
      });
    },
    //获取统计信息
    getStatisticInfo() {
      console.log("setI");
      this.$http
        .get(
          `${this.$basePath}?service=App.Statistics.ListStatisticAttendance&api=93`,
          {
            params: { token: this.token }
          }
        )
        .then(res => {
          if (res.ret == 200) {
            console.log("统计信息", res);
            this.leftsideList = res.data;
          } else {
            this.$toast({ message: res.msg });
          }
        });
    },
    //监察车或人是否在线状态
    checkOnline1() {
      console.log("检车");
      var interval = 600000; //间隔时间（毫秒）
      setInterval(function() {
        var now = new Date().getTime();
        var car_info = this.car_info;
        if (car_info.length > 0) {
          for (let i in car_info) {
            var updateTime = car_info[i].updateTime;
            if (updateTime && typeof updateTime === "number") {
              if (
                updateTime.toString().length == 10 ||
                updateTime.toString().length == 13
              ) {
                if (updateTime.toString().length == 10) {
                  updateTime = updateTime * 1000;
                }
                var difference = now - updateTime;
                if (
                  difference > interval &&
                  car_info[i].is_online &&
                  car_info[i].is_online != 2
                ) {
                  car_info[i].is_online = 2;
                  this.showAndSaveMarker(car_info[i], "car");
                }
              }
            }
          }
        }
        var user_info = this.car_info;
        if (user_info.length > 0) {
          for (let i in user_info) {
            var updateTime = user_info[i].updateTime;
            if (updateTime && typeof updateTime === "number") {
              if (
                updateTime.toString().length == 10 ||
                updateTime.toString().length == 13
              ) {
                if (updateTime.toString().length == 10) {
                  updateTime = updateTime * 1000;
                }
                var difference = now - updateTime;
                if (
                  difference > interval &&
                  user_info[i].is_online &&
                  user_info[i].is_online != 2
                ) {
                  user_info[i].is_online = 2;
                  this.showAndSaveMarker(user_info[i], "user");
                }
              }
            }
          }
        }
      }, interval);
    },
    /**地图操作 */
    // 初始化百度地图
    initBmap() {
      this.bmap = new BMap.Map("bmap", { drawer: BMAP_SVG_DRAWER });
      var point = new BMap.Point(108.953098279, 34.2777998978);
      this.bmap.centerAndZoom(point, 5);

      this.bmap.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
      this.bmap.setDefaultCursor("pointer");
    },
    //查看历史轨迹
    viewGps(id, lng, lat, type) {
      console.log("id", id, lng, lat, type);
      this.$router.push({
        //核心语句
        path: "/monitortrack", //跳转的路径
        query: {
          //路由传参时push和query搭配使用 ，作用时传递参数
          id,
          lng,
          lat,
          type
        }
      });
    },
    //获取指定片区围栏
    getAreaCoordinates(type) {
      var params = { token: this.token };
      var info = "",
        url = "";
      var object = null;
      switch (type) {
        case "company":
          url = `${this.$basePath}?service=App.Fence.ListProjectCompanyArea&api=85`;
          info = "项目公司围栏信息";
          object = this.company_info;
          break;
        case "project":
          url = `${this.$basePath}?service=App.Fence.ListProjectArea&api=85`;
          info = "项目部围栏信息";
          object = this.project_info;
          break;
        case "district":
          url = `${this.$basePath}?service=App.Fence.ListDistrictArea&api=85`;
          info = "片区围栏信息";
          object = this.district_info;
          break;
        case "user":
          url = `${this.$basePath}?service=App.Fence.ListDutyArea&api=85`;
          info = "保洁员围栏信息";
          object = this.user_info;
          break;
        case "car":
          url = `${this.$basePath}?service=App.Fence.ListCarArea&api=85`;
          info = "车辆围栏信息";
          object = this.car_info;
          break;
      }
      //获取围栏信息
      this.$http.post(url, params).then(res => {
        if (res.ret == 200) {
          // console.info(info, res.data);
          for (let j in res.data) {
            if (typeof res.data[j].area == "string") {
              let area = eval("(" + res.data[j].area + ")");
              for (let i in object) {
                if (type == "car") {
                  if (object[i].id == res.data[j].car[0].id) {
                    object[i].area_coordinates = area;
                    //console.log("单个车辆", object[i].area_coordinates);
                    //把对应的围栏信息传给地图围栏函数
                    this.showAndSaveFence(object[i], type);
                    break;
                  }
                } else if (type == "company") {
                  if (object[i].id == res.data[j].project_company_id) {
                    object[i].area_coordinates = area;
                    // console.log("单个项目公司", object[i].area_coordinates);
                    this.showAndSaveFence(object[i], type);
                    break;
                  }
                } else if (type == "project") {
                  if (object[i].id == res.data[j].project_id) {
                    object[i].area_coordinates = area;
                    //console.log("单个项目部", object[i].area_coordinates);
                    this.showAndSaveFence(object[i], type);
                    break;
                  }
                } else if (type == "district") {
                  if (object[i].id == res.data[j].district_id) {
                    object[i].area_coordinates = area;
                    //console.log("单个项目片区", object[i].area_coordinates);
                    this.showAndSaveFence(object[i], type);
                    break;
                  }
                } else if (type == "user") {
                  if (object[i].id == res.data[j].user_id) {
                    object[i].area_coordinates = area;
                    //console.log("单个责任区", object[i].area_coordinates);
                    this.showAndSaveFence(object[i], type);
                    break;
                  }
                }
              }
            }
          }
        } else {
          this.$toast({ message: res.msg });
        }
      });
    },
    // 获取车辆或人员的初始位置
    getCoordinates(type) {
      //console.info("获取初始坐标",type," ",id)
      var info = "",
        url = "";
      var object = null;
      switch (type) {
        case "user":
          url = `${this.$basePath}?service=App.GetUserOrCar.GetUserInitLocation&api=93`;
          info = "保洁员和管理员初始位置";
          object = this.user_info;
          break;
        case "car":
          url = `${this.$basePath}?service=App.GetUserOrCar.GetCarInitLocation&api=93`;
          info = "车辆初始位置";
          object = this.car_info;
          break;
      }
      var ids = "";
      for (let i = 0; i < object.length; i++) {
        ids += object[i].id;
        if (i != object.length - 1) {
          ids += ",";
        }
      }
      var params = {
        id: ids,
        token: this.token
      };
      //获取初始坐标
      this.$http.post(url, params).then(res => {
        if (res.ret == 200) {
          //console.info(info, res.data);
          for (let i in object) {
            if (res.data[object[i].id]) {
              let position = null;
              if (typeof res.data[object[i].id] == "string") {
                position = JSON.parse(res.data[object[i].id]);
              }
              //console.info("position:", position);
              object[i].is_online = position.is_online;
              if (type == "user") {
                object[i].batV = position.batv;
                object[i].csq = position.csq;
                object[i].updateTime = position.deviceTime;
                object[i].coordinates = {
                  lng: position.longitude,
                  lat: position.latitude
                };
              } else if (type == "car") {
                object[i].updateTime = position.sendTime;
                object[i].coordinates = {
                  lng: position.longitude,
                  lat: position.latitude,
                  direction: position.direction,
                  mileage: position.mileage,
                  velocity: position.velocity
                };
              }
              this.showAndSaveMarker(object[i], type);
            }
          }
        }
      });
    },
    // 在地图上人或车的位置标注 并 缓存标注对象人车坐标
    showAndSaveMarker(object, type) {
      //console.info(object, type);
      var that = this;
      if (type == "user" && object.is_leader == 1) {
        // console.info(object, type);
        type = "manager";
      }
      //
      var icon_marker = "";
      var size_icon = null;
      var size_label = null;
      switch (type) {
        case "user":
        case "manager":
          icon_marker = that.icon_map[type][object.is_online];
          size_icon = new BMap.Size(15, 15);
          size_label = new BMap.Size(15, 30);
          break;
        case "car":
          icon_marker = that.icon_map[type][object.is_online];
          size_icon = new BMap.Size(40, 40);
          size_label = new BMap.Size(15, 30);
          break;
        case "trash":
          icon_marker = that.icon_map[type];
          size_icon = new BMap.Size(15, 0);
          size_label = new BMap.Size(15, 30);
          break;
      }
      // if (object.photo) {
      //   icon_marker = object.photo;
      // }
      //获取中心点
      var fence = object.coordinates;
      if (typeof fence == "string") {
        fence = eval("(" + fence + ")");
      }
      var coordinates = object.coordinates;
      if (typeof coordinates == "string") {
        coordinates = eval("(" + coordinates + ")");
      }
      var point = new BMap.Point(coordinates.lng, coordinates.lat);

      var convertor = new BMap.Convertor();
      var pointArr = [];
      pointArr.push(point);
      convertor.translate(pointArr, 1, 5, function(data) {
        if (data.status === 0) {
          if (object.marker) {
            that.bmap.removeOverlay(object.marker);
          }
          var icon = new BMap.Icon(icon_marker, new BMap.Size(30, 30), {
            anchor: size_icon
          });
          var markerOpt = {};
          if (coordinates.direction) {
            markerOpt = { icon: icon, rotation: coordinates.direction };
          } else {
            markerOpt = { icon: icon, rotation: 0 };
          }
          object.updateTime = that.timeFormat(object.updateTime);
          // console.log("更新时间", object.updateTime);
          var marker = new BMap.Marker(data.points[0], markerOpt);

          var is_online_text = { 1: "在线", 2: "离线" };
          if (type == "user" || type == "manager") {
            var csq = "-";
            if (object.csq || object.csq == 0) {
              csq = object.csq + " %";
            }
            var batV = "-";
            if (object.batV || object.batV == 0) {
              batV = object.batV + " %";
            }
            var opts = {
              width: 200, // 信息窗口宽度
              height: 180 // 信息窗口高度
              // 信息窗口标题
            };
            var html =
              "<table width='100%' style='font-size: 10px;'>" +
              "<tr><td align='right'>姓名</td><td>" +
              object.name +
              "</td></tr>" +
              "<tr><td align='right'>部门</td><td>" +
              object.department_name +
              "</td></tr>" +
              "<tr><td align='right'>硬件</td><td>" +
              object.imei +
              "</td></tr>" +
              "</td></tr>" +
              "<tr><td align='right'>状态</td><td>" +
              is_online_text[object.is_online] +
              "</td></tr>" +
              "<tr><td align='right'>信号强度</td><td class='csq'>" +
              csq +
              "</td></tr>" +
              "<tr><td align='right'>电池电量</td><td class='batV'>" +
              batV +
              "<tr><td align='right'>更新时间</td><td>" +
              object.updateTime +
              "</td></tr>" +
              "</table>" +
              "</div><input id='Button1' class='historybut' style='outline:none;border:none;color:#f58914;font-size: 14px; text-align:center; padding-top:10px;'    value='查看历史轨迹' onclick='viewGps(" +
              object.id +
              "," +
              marker.point.lng +
              "," +
              marker.point.lat +
              "," +
              JSON.stringify(type) +
              ")'/> ";

            var infoWindow = new BMap.InfoWindow(html, opts);
            object.infoWindow = infoWindow;
            object.infoWindowPoint = data.points[0];
            marker.addEventListener("click", function(e) {
              //设置中心点，移到到中心点
              var center = that.getCenterPoint(fence);
              that.bmap.panTo(center);
              that.bmap.centerAndZoom(center, 12);
              that.bmap.openInfoWindow(infoWindow, data.points[0]);
            });
          } else if (type == "car") {
            var velocity = "-";
            if (coordinates.velocity || coordinates.velocity == 0) {
              velocity = coordinates.velocity.toFixed(0) + " km/h";
            }
            var mileage = "-";
            if (coordinates.mileage || coordinates.mileage == 0) {
              mileage = coordinates.mileage.toFixed(0) + " km";
            }
            var html =
              "<table width='100%' style='font-size: 10px;'>" +
              "<tr><td align='right'>车牌</td><td>" +
              object.name +
              "</td></tr>" +
              "<tr><td align='right'>部门</td><td>" +
              object.department_name +
              "</td></tr>" +
              "<tr><td align='right'>硬件</td><td>" +
              object.simNo +
              "</td></tr>" +
              "<tr><td align='right'>状态</td><td>" +
              is_online_text[object.is_online] +
              "</td></tr>" +
              "<tr><td align='right'>里程</td><td>" +
              mileage +
              "</td></tr>" +
              /*"<tr><td align='right'>油量</td><td>-</td></tr>" +*/
              "<tr><td align='right'>速度</td><td>" +
              velocity +
              "</td></tr>" +
              "<tr><td align='right'>更新时间</td><td>" +
              object.updateTime +
              "</td></tr>" +
              "</table>" +
              "</div><input id='Button1' class='historybut' style='outline:none;border:none;color:#f58914;font-size: 14px; text-align:center; padding-top:10px;'    value='查看历史轨迹' onclick='viewGps(" +
              object.id +
              "," +
              marker.point.lng +
              "," +
              marker.point.lat +
              "," +
              JSON.stringify(type) +
              ")'/> ";
            var infoWindow = new BMap.InfoWindow(html);
            object.infoWindow = infoWindow;
            object.infoWindowPoint = data.points[0];
            marker.addEventListener("click", function(e) {
              that.bmap.openInfoWindow(infoWindow, data.points[0]);
            });
          }
          object.marker = marker; //缓存
          if (type != "trash") {
            var label = new BMap.Label(object.name, { offset: size_label });
            if (type == "car") {
              label.setStyle({
                color: "#000",
                borderColor: "transparent",
                backgroundColor: "#fdbe21",
                borderRadius: "5px",
                maxWidth: "none", //去除bootstrap中样式
                fontSize: "10px",
                height: "16px",
                lineHeight: "16px",
                fontFamily: "微软雅黑"
              });
            } else if (type == "manager" || type == "user")
              label.setStyle({
                color: "#f00",
                borderColor: "transparent",
               
                borderRadius: "5px",
                maxWidth: "none", //去除bootstrap中样式
                fontSize: "10px",
                height: "16px",
                lineHeight: "16px",
                fontFamily: "微软雅黑"
              });
            marker.setLabel(label);
          }
          that.bmap.addOverlay(marker);
          if (object.markerShow) {
            marker.show();
          } else {
            marker.hide();
          }
        }
      });
    },

    // 在地图上显示电子围栏 并 缓存围栏覆盖物
    showAndSaveFence(object, type) {
      var that = this;
      //console.log("画围栏", object, type);
      var fence = object.area_coordinates;
      if (typeof fence == "string") {
        fence = eval("(" + fence + ")");
      }
      // var center = this.getCenterPoint(fence);

      // this.bmap.panTo(center);
      var points = [];
      for (let i in fence) {
        var point = new BMap.Point(fence[i].lng, fence[i].lat);
        points.push(point);
      }
      var layerColor = {
        company: "#e60012 ",
        project: "#8957a1",
        district: "#ff5065",
        user: "#40a000",
        car: "#ff6600",
        park: "#516ca6",
        dump: "#00a0e9"
      };
      if (points.length > 1) {
        //console.info("showAndSaveFence", object, type);
        var style_polygon = {
          strokeColor: layerColor[type], //边线颜色。
          strokeWeight: 2, //边线的宽度，以像素为单位。
          //边线透明度，取值范围0 - 1。
          fillColor: "#00ff00", //填充颜色。
          fillOpacity: 0.1, //填充的透明度，取值范围0 - 1。
          strokeStyle: "solid" //边线的样式，solid或dashed。
        };
        var polygon = new BMap.Polygon(points, style_polygon);
        object.overlay = polygon; //缓存
        var opts = {
          width: 200, // 信息窗口宽度
          height: 40, // 信息窗口高度
          title: object.name // 信息窗口标题
        };
        var infoWindow = new BMap.InfoWindow("", opts);

        polygon.addEventListener("click", function(e) {
          //移到到区域中心点
          var center = that.getCenterPoint(fence);
          that.bmap.panTo(center);
          that.bmap.centerAndZoom(center, 13);
          that.bmap.openInfoWindow(
            infoWindow,
            new BMap.Point(fence[0].lng, fence[0].lat)
          );
        });
        var center1 = that.getCenterPoint(polygon.getPath());
        var label = new BMap.Label(object.name, {
          offset: new BMap.Size(-12, 0),
          position: center1
        });
        label.setStyle({
          color: layerColor[type],
          borderColor: "transparent",
          backgroundColor: "transparent",
          maxWidth: "none", //去除bootstrap中样式
          fontSize: "14px",
          height: "16px",
          lineHeight: "16px",
          fontFamily: "微软雅黑"
        });
        that.bmap.addOverlay(polygon);
        that.bmap.addOverlay(label);
        object.overlay = polygon; //缓存覆盖物对象
        object.overlayLabel = label;
      }
    },

    // 获取多边形中心点坐标
    getCenterPoint(path) {
      var x = 0.0;
      var y = 0.0;
      if (path) {
        for (var i = 0; i < path.length; i++) {
          x = x + parseFloat(path[i].lng);
          y = y + parseFloat(path[i].lat);
        }
        x = x / path.length;
        y = y / path.length;
        return new BMap.Point(x, y);
      }
    },

    // 显示或隐藏覆盖物
    showOrHide(type, target) {
      var object = null;
      switch (type) {
        case "company":
          object = this.company_info;
          this.successiconshow = !this.successiconshow;
          var checked = this.successiconshow;

          break;
        case "project":
          object = this.project_info;
          this.successiconshow1 = !this.successiconshow1;
          var checked = this.successiconshow1;
          break;
        case "district":
          object = this.district_info;
          this.successiconshow2 = !this.successiconshow2;
          var checked = this.successiconshow2;
          break;
        case "user":
          object = this.user_info;
          this.successiconshow3 = !this.successiconshow3;

          var checked = this.successiconshow3;
          break;
        case "car":
          object = this.car_info;
          this.successiconshow9 = !this.successiconshow9;
          var checked = this.successiconshow9;
          break;
        case "park":
          object = this.park_info;
          this.successiconshow6 = !this.successiconshow6;
          var checked = this.successiconshow6;
          break;
        case "dump":
          object = this.dump_info;
          this.successiconshow7 = !this.successiconshow7;
          var checked = this.successiconshow7;
          break;
      }
      console.info("操作对象", checked, type, object);
      for (let i in object) {
        if (checked) {
          if (object[i][target]) {
            object[i][target].show();
            if (target == "overlay") {
              object[i]["overlayLabel"].show();
            } else if (target == "marker") {
              object[i].markerShow = true;
            }
          }
          // if (object[i].overlay) {
          //   object[i].overlay.show();

          //   //  this.bmap.addOverlay(object[i].overlay)
          // }
        } else {
          if (object[i][target]) {
            object[i][target].hide();
            if (target == "overlay") {
              object[i]["overlayLabel"].hide();
            } else if (target == "marker") {
              object[i].markerShow = false;
            }
          }
          // if (object[i].overlay) {
          //   // this.bmap.removeOverlay(object[i].overlay)
          //   object[i].overlay.hide();
          // }
        }
      }
      //   for (let i in object) {
      //     let checked = $(_this).prop("checked")
      //     if (checked) {
      //       if (object[i].overlay) {
      //         object[i].overlay.show();
      //       }
      //     } else {
      //       if (object[i].overlay) {
      //         object[i].overlay.hide();
      //       }
      //     }
      //   }
    },

    // 显示或隐藏人员和车辆坐标
    showOrHideCarAndUser(type, target) {
      var object = null;
      switch (type) {
        case "user":
          object = this.user_info;
          this.successiconshow4 = !this.successiconshow4;
          var checked = this.successiconshow4;
          break;
        case "car":
          object = this.car_info;
          this.successiconshow5 = !this.successiconshow5;
          var checked = this.successiconshow5;
          break;
        case "trash":
          object = this.trash_info;
          this.successiconshow8 = !this.successiconshow8;
          var checked = this.successiconshow8;
          break;
      }
      console.info("操作对象", checked, type, object);
      for (let i in object) {
        if (checked) {
          if (object[i][target]) {
            object[i][target].show();
            if (target == "marker") {
              object[i].markerShow = true;
            }
          }
        } else {
          if (object[i][target]) {
            object[i][target].hide();
            if (target == "marker") {
              object[i].markerShow = false;
            }
          }
        }
      }
    },
    // 点击激活此项
    activeThis(type, id) {
      console.info(type, id);

      var object = null;
      switch (type) {
        case "company":
          object = this.company_info;
          break;
        case "project":
          object = this.project_info;
          break;
        case "district":
          object = this.district_info;
          break;
        case "person":
          object = this.user_info;
          break;
        case "car":
          object = this.car_info;
          break;
        case "park":
          object = this.park_info;
          break;
        case "dump":
          object = this.dump_info;
          break;
        case "trash":
          object = this.trash_info;
          break;
      }

      for (let i in object) {
        if (object[i].id == id) {
          if (type == "trash") {
            if (object[i].marker) {
              this.bmap.centerAndZoom(object[i].marker.getPosition(), 15);
            } else {
              this.$toast({ message: "没有相关数据" });
            }
          } else if (type == "person" || type == "car") {
            this.bmap.openInfoWindow(
              object[i].infoWindow,
              object[i].infoWindowPoint
            );
            if (object[i].marker) {
              this.bmap.centerAndZoom(object[i].marker.getPosition(), 15);
            } else if (object[i].overlay) {
              this.bmap.setViewport(object[i].overlay.getPath()); // 调整视野
            }
          } else {
            if (object[i].overlay) {
              this.bmap.setViewport(object[i].overlay.getPath()); // 调整视野
            } else {
              this.$toast({ message: "没有相关数据" });
            }
          }
          break;
        }
      }
      //if (type == "trash" || type == "car") {
      // for (let i in object) {
      //   if (object[i].id == id) {
      //     if (
      //       object[i].area_coordinates &&
      //       object[i].area_coordinates.length > 0
      //     ) {
      //       var center = this.getCenterPoint(object[i].area_coordinates);
      //       this.bmap.panTo(center);
      //       break;
      //     } else {
      //       this.$toast({ message: "没有相关数据" });
      //     }
      //   }
      // }
    },
    // 获取公司列表
    getCompanys() {
      var params = {
        token: this.token
      };
      this.$http
        .get(
          `${this.$basePath}?service=App.Organizational.ListProjectCompany&api=84`,
          {
            params: params
          }
        )
        .then(res => {
          if (res.ret == 200) {
            console.log("项目公司列表", res);
            if (this.user_department_type == 3) {
              console.log(3);
              // 项目公司经理只能查看自己公司的公司
              for (let i in res.data) {
                console.log(res.data[i].id, this.user_department_id);
                if (res.data[i].id == this.user_department_id) {
                  console.log(4);
                  let company = {
                    id: res.data[i].id,
                    name: res.data[i].name,
                    area_coordinates: null,
                    overlay: null
                  };
                  this.company_info.push(company);
                }
              }
              console.log("type为3", this.company_info);
              this.getAreaCoordinates("company");
              this.getParks();
              this.getDumps();
              this.getProjects();
              var result = this.company_info.map(o => {
                return {
                  text: o.name,
                  value: o.id
                };
              });
              result.unshift({ text: "选择项目公司", value: 0 });
              this.ProjectCompanycolumns = result;
              console.log("选择项目公司", this.ProjectCompanycolumns);
            } else if (this.user_department_type == 1) {
              // 集团管理员查看所有
              for (let i in res.data) {
                let company = {
                  id: res.data[i].id,
                  name: res.data[i].name,
                  area_coordinates: null,
                  overlay: null
                };
                this.company_info.push(company);
              }
              this.getAreaCoordinates("company");
              this.getParks();
              this.getDumps();
              this.getProjects();
              var result = this.company_info.map(o => {
                return {
                  text: o.name,
                  value: o.id
                };
              });
              result.unshift({ text: "选择项目公司", value: 0 });
              this.ProjectCompanycolumns = result;
              console.log("选择项目公司", this.ProjectCompanycolumns);
            }
          } else {
            this.$toast({ message: res.msg });
          }
        });
    },
    // 获取项目部列表
    getProjects() {
      var params = {
        token: this.token
      };
      this.$http
        .get(
          `${this.$basePath}?service=App.Organizational.ListProject&api=84`,
          {
            params: params
          }
        )
        .then(res => {
          if (res.ret == 200) {
            console.log("项目部列表", res);
            if (this.user_department_type == 5) {
              // 项目公司部经理只能查看自己的项目部
              for (let i in res.data) {
                if (res.data[i].id == this.user_department_id) {
                  let project = {
                    id: res.data[i].id,
                    name: res.data[i].name,
                    parent_id: res.data[i].project_company_id,
                    area_coordinates: null,
                    overlay: null
                  };
                  this.project_info.push(project);
                }
              }
              console.log("type5", this.project_info);
              this.getAreaCoordinates("project");
              this.getCars(); //车辆挂在项目部下面
              this.getDistricts();
              this.getTrash(); //垃圾桶挂在项目部下面
              var result = this.project_info.map(o => {
                return {
                  text: o.name,
                  value: o.id
                };
              });
              result.unshift({ text: "选择项目部", value: 0 });
              this.Projectcolumns = result;
              console.log("选择项目部", this.Projectcolumns);
            } else if (this.user_department_type == 3) {
              // 项目公司经理只能查看自己公司的项目部
              for (let i in res.data) {
                if (res.data[i].project_company_id == this.user_department_id) {
                  let project = {
                    id: res.data[i].id,
                    name: res.data[i].name,
                    parent_id: res.data[i].project_company_id,
                    area_coordinates: null,
                    overlay: null
                  };
                  this.project_info.push(project);
                }
              }
              this.getAreaCoordinates("project");
              this.getCars(); //车辆挂在项目部下面
              this.getDistricts();
              this.getTrash(); //垃圾桶挂在项目部下面
              var result = this.project_info.map(o => {
                return {
                  text: o.name,
                  value: o.id
                };
              });
              result.unshift({ text: "选择项目部", value: 0 });
              this.Projectcolumns = result;
              console.log("选择项目部", this.Projectcolumns);
            } else if (this.user_department_type == 1) {
              //获取项目部的围栏信息
              for (let i in res.data) {
                let project = {
                  id: res.data[i].id,
                  name: res.data[i].name,
                  parent_id: res.data[i].project_company_id,
                  area_coordinates: null,
                  overlay: null
                };
                this.project_info.push(project);
              }
              this.getAreaCoordinates("project");
              this.getCars(); //车辆挂在项目部下面
              this.getDistricts();
              this.getTrash(); //垃圾桶挂在项目部下面
              // var result = this.project_info.map(o => {
              //   return {
              //     text: o.name,
              //     value: o.id
              //   };
              // });
              // result.unshift({ text: "请选择项目部", value: 0 });
              // this.Projectcolumns = result;
              // console.log("请选择项目部", this.Projectcolumns);
            }
          } else {
            this.$toast({ message: res.msg });
          }
        });
    },
    // 获取片区列表
    getDistricts() {
      var params = {
        token: this.token
      };
      this.$http
        .get(
          `${this.$basePath}?service=App.Organizational.ListDistrict&api=84`,
          {
            params: params
          }
        )
        .then(res => {
          if (res.ret == 200) {
            console.log("项目片区列表", res);
            if (
              this.user_department_type == 5 ||
              this.user_department_type == 3
            ) {
              // 项目公司部经理只能查看自己项目部的片区
              // 项目公司经理只能查看自己公司的片区
              var project_info = this.project_info;
              for (let i in res.data) {
                for (let j in project_info) {
                  if (project_info[j].id == res.data[i].project_id) {
                    let district = {
                      id: res.data[i].id,
                      name: res.data[i].name,
                      parent_id: res.data[i].project_id,
                      pparent_id: project_info[j].parent_id,
                      area_coordinates: null,
                      overlay: null
                    };
                    this.district_info.push(district);
                  }
                }
              }
              console.log("片区信息");
              this.getAreaCoordinates("district");
              this.getUsers();
              this.checkOnline1();
              var result = this.district_info.map(o => {
                return {
                  text: o.name,
                  value: o.id
                };
              });
              result.unshift({ text: "选择项目片区", value: 0 });
              this.Districtcolumns = result;
              console.log("选择项目片区", this.Districtcolumns);
            } else if (this.user_department_type == 1) {
              // 集团公司高层可查看全部片区
              for (let i in res.data) {
                let district = {
                  id: res.data[i].id,
                  name: res.data[i].name,
                  parent_id: res.data[i].project_id,
                  area_coordinates: null,
                  overlay: null
                };
                var project_info = this.project_info;
                for (let j in project_info) {
                  if (project_info[j].id == district.parent_id) {
                    district.pparent_id = project_info[j].parent_id;
                    break;
                  }
                }
                this.district_info.push(district);
              }
              this.getAreaCoordinates("district");
              //人员挂在片区下面
              this.getUsers();
              this.checkOnline1();
            } else if (this.user_department_type == 6) {
              // 管理员显示自己片区
              for (let i in res.data) {
                if (res.data[i].id == this.user_department_id) {
                  let district = {
                    id: res.data[i].id,
                    name: res.data[i].name,
                    parent_id: res.data[i].project_id,
                    area_coordinates: null,
                    overlay: null
                  };
                  this.district_info.push(district);
                }
              }
              this.getAreaCoordinates("district");
              //人员挂在片区下面
              this.getUsers();
              this.checkOnline1();
            }
          } else {
            this.$toast({ message: res.msg });
          }
        });
    },
    // 获取人员列表
    getUsers() {
      var params = {
        token: this.token
      };
      this.$http
        .get(`${this.$basePath}?service=App.GetUserOrCar.GetUserList&api=93`, {
          params: params
        })
        .then(res => {
          console.log("保洁员列表", res);
          if (res.ret == 200) {
            if (
              this.user_department_type == 5 ||
              this.user_department_type == 3
            ) {
              // 项目公司部经理只能查看自己项目部的人员
              // 项目公司经理只能查看自己公司的人员
              for (let i in res.data) {
                var district_info = this.district_info;
                if (res.data[i].department_type == 6) {
                  for (let j in district_info) {
                    if (district_info[j].id == res.data[i].department_id) {
                      let user = {
                        id: res.data[i].id,
                        imei: res.data[i].imei,
                        name: res.data[i].name,
                        is_leader: res.data[i].is_leader,
                        department_id: res.data[i].department_id,
                        department_name: res.data[i].department_name,
                        pparent_id: district_info[j].parent_id,
                        ppparent_id: district_info[j].pparent_id,
                        photo: res.data[i].photo,
                        area_coordinates: null,
                        coordinates: null,
                        overlay: null,
                        markerShow: true
                      };
                      this.user_info.push(user);
                    }
                  }
                }
              }
              this.getAreaCoordinates("user");
              //加载人的初始位置
              if (this.user_info.length != 0) {
                this.getCoordinates("user");
              }
            } else if (this.user_department_type == 1) {
              // 集团公司高层可查看全部人员
              for (let i in res.data) {
                let user = {
                  id: res.data[i].id,
                  imei: res.data[i].imei,
                  name: res.data[i].name,
                  is_leader: res.data[i].is_leader,
                  department_id: res.data[i].department_id,
                  department_name: res.data[i].department_name,
                  photo: res.data[i].photo,
                  area_coordinates: null,
                  coordinates: null,
                  overlay: null,
                  markerShow: true
                };
                if (res.data[i].department_type == 6) {
                  var district_info = this.district_info;
                  for (let j in district_info) {
                    if (district_info[j].id == user.department_id) {
                      user.pparent_id = district_info[j].parent_id;
                      user.ppparent_id = district_info[j].pparent_id;
                      break;
                    }
                  }
                  this.user_info.push(user);
                }
              }
              this.getAreaCoordinates("user");
              //加载人的初始位置
              if (this.user_info.length != 0) {
                this.getCoordinates("user");
              }
              //人得实时数据
              this.personwebsocket();
              this.managerwebsocket();
            } else if (this.user_department_type == 6) {
              for (let i in res.data) {
                if (
                  res.data[i].department_id == this.user_department_id &&
                  res.data[i].department_type == 6
                ) {
                  let user = {
                    id: res.data[i].id,
                    imei: res.data[i].imei,
                    name: res.data[i].name,
                    is_leader: res.data[i].is_leader,
                    department_id: res.data[i].department_id,
                    department_name: res.data[i].department_name,
                    photo: res.data[i].photo,
                    area_coordinates: null,
                    coordinates: null,
                    overlay: null,
                    markerShow: true
                  };
                  this.user_info.push(user);
                }
              }
              console.log("人员", this.user_info);
              // 管理员只可看自己的保洁员
              this.getAreaCoordinates("user");
              //加载人的初始位置
              if (this.user_info.length != 0) {
                this.getCoordinates("user");
              }
              //人得实时数据
              this.personwebsocket();
              this.managerwebsocket();
              var result = this.user_info.map(o => {
                return {
                  text: o.name,
                  value: o.id
                };
              });
              result.unshift({ text: "选择责任区", value: 0 });
              this.DutyAreacolumns = result;
              console.log("选择责任区", this.DutyAreacolumns);
            }
          } else {
            this.$toast({ message: res.msg });
          }
        });
    },
    // 获取车辆列表
    getCars() {
      var params = {
        token: this.token
      };
      this.$http
        .get(`${this.$basePath}?service=App.GetUserOrCar.GetCarList&api=93`, {
          params: params
        })
        .then(res => {
          console.log("车辆列表", res);
          if (res.ret == 200) {
            if (
              this.user_department_type == 5 ||
              this.user_department_type == 3
            ) {
              // 项目公司部经理只能查看自己项目部的车辆
              // 项目公司经理只能查看自己公司的车辆
              for (let i in res.data) {
                var project_info = this.project_info;
                for (let j in project_info) {
                  if (project_info[j].id == res.data[i].project_id) {
                    let car = {
                      id: res.data[i].id,
                      simNo: res.data[i].simNo,
                      department_id: res.data[i].project_id,
                      pparent_id: project_info[j].parent_id,
                      name: res.data[i].plate_number,
                      department_name: res.data[i].project_name,
                      photo: res.data[i].photo,
                      area_coordinates: null,
                      coordinates: null,
                      overlay: null,
                      markerShow: true
                    };
                    this.car_info.push(car);
                  }
                }
              }
              this.getAreaCoordinates("car");
              //获取车辆的初始位置
              if (this.car_info.length != 0) {
                this.getCoordinates("car");
              }

              //this.initWebSocket();
              this.carwebsocket();
              var result = this.car_info.map(o => {
                return {
                  text: o.name,
                  value: o.id
                };
              });
              result.unshift({ text: "选择车辆", value: 0 });
              this.ProjectCarcolumns = result;
              console.log("选择车辆", this.ProjectCarcolumns);
            } else if (this.user_department_type == 1) {
              // 集团公司高层可查看全部车辆
              for (let i in res.data) {
                let car = {
                  id: res.data[i].id,
                  simNo: res.data[i].simNo,
                  department_id: res.data[i].project_id,
                  name: res.data[i].plate_number,
                  department_name: res.data[i].project_name,
                  photo: res.data[i].photo,
                  area_coordinates: null,
                  coordinates: null,
                  overlay: null,
                  markerShow: true
                };
                var project_info = this.project_info;
                for (let j in project_info) {
                  if (project_info[j].id == car.department_id) {
                    car.pparent_id = project_info[j].parent_id;
                    break;
                  }
                }
                this.car_info.push(car);
              }
              this.getAreaCoordinates("car");
              //获取车辆的初始位置
              if (this.car_info.length != 0) {
                this.getCoordinates("car");
              }
              //this.initWebSocket();
              this.carwebsocket();
              // var result = this.car_info.map(o => {
              //   return {
              //     text: o.name,
              //     value: o.id
              //   };
              // });
              // result.unshift({ text: "请选择项目部车辆", value: 0 });
              // this.ProjectCarcolumns = result;
              // console.log("请选择项目部车辆", this.ProjectCarcolumns);
            }

            // for (let i in res.data) {
            //   let car = {
            //     id: res.data[i].id,
            //     simNo: res.data[i].simNo,
            //     department_id: res.data[i].project_id,
            //     name: res.data[i].plate_number,
            //     deparment_name: res.data[i].project_name,
            //     photo: res.data[i].photo,
            //     area_coordinates: null,
            //     coordinates: null,
            //     overlay: null
            //   };
            //   this.car_info.push(car);
            //   // console.log("车信息", this.car_info);
            // }
            // this.getAreaCoordinates("car");
            // //获取车辆的初始位置
            // this.getCoordinates("car");
            // //this.initWebSocket();
            // this.carwebsocket();
          } else {
            this.$toast({ message: res.msg });
          }
        });
    },
    //获取停车场
    getParks() {
      var params = {
        token: this.token
      };
      this.$http
        .get(`${this.$basePath}?service=App.Fence.ListParkArea&api=85`, {
          params: params
        })
        .then(res => {
          if (res.ret == 200) {
            console.log("停车场列表", res);
            if (this.user_department_type == 3) {
              // 项目公司经理只能查看自己公司的停车场
              for (let i in res.data) {
                if (res.data[i].project_company_id == this.user_department_id) {
                  let park = {
                    id: res.data[i].id,
                    name: res.data[i].areaname,
                    parent_id: res.data[i].project_company_id,
                    area_coordinates: null,
                    overlay: null
                  };
                  if (typeof res.data[i].area == "string") {
                    park.area_coordinates = JSON.parse(res.data[i].area);
                  }
                  this.park_info.push(park);
                  this.showAndSaveFence(park, "park");
                }
              }
              var result = this.park_info.map(o => {
                return {
                  text: o.name,
                  value: o.id
                };
              });
              result.unshift({ text: "选择停车场", value: 0 });
              this.ProjectCompanyParkcolumns = result;
              console.log("选择停车场", this.ProjectCompanyParkcolumns);
            } else if (this.user_department_type == 1) {
              // 集团公司高层可查看全部停车场
              for (let i in res.data) {
                let park = {
                  id: res.data[i].id,
                  name: res.data[i].areaname,
                  parent_id: res.data[i].project_company_id,
                  area_coordinates: null,
                  overlay: null
                };
                if (typeof res.data[i].area == "string") {
                  park.area_coordinates = JSON.parse(res.data[i].area);
                }
                this.park_info.push(park);
                this.showAndSaveFence(park, "park");
              }
              // var result = this.park_info.map(o => {
              //   return {
              //     text: o.name,
              //     value: o.id
              //   };
              // });
              // result.unshift({ text: "请选择项目公司停车场", value: 0 });
              // this.ProjectCompanyParkcolumns = result;
              // console.log(
              //   "请选择项目公司停车场",
              //   this.ProjectCompanyParkcolumns
              // );
            }
          } else {
            this.$toast({ message: res.msg });
          }
        });
    },
    //获取回收站
    getDumps() {
      var params = {
        token: this.token
      };
      this.$http
        .get(`${this.$basePath}?service=App.Fence.ListDumpArea&api=85`, {
          params: params
        })
        .then(res => {
          if (res.ret == 200) {
            console.log("回收站列表", res);
            if (this.user_department_type == 3) {
              // 项目公司经理只能查看自己公司的停车场
              for (let i in res.data) {
                if (res.data[i].project_company_id == this.user_department_id) {
                  let dump = {
                    id: res.data[i].id,
                    name: res.data[i].areaname,
                    parent_id: res.data[i].project_company_id,
                    area_coordinates: null,
                    overlay: null
                  };
                  if (typeof res.data[i].area == "string") {
                    dump.area_coordinates = JSON.parse(res.data[i].area);
                  }
                  this.dump_info.push(dump);
                  this.showAndSaveFence(dump, "dump");
                }
              }
              var result = this.dump_info.map(o => {
                return {
                  text: o.name,
                  value: o.id
                };
              });
              result.unshift({ text: "选择回收站", value: 0 });
              this.ProjectCompanyDumpcolumns = result;
              console.log("选择回收站", this.ProjectCompanyDumpcolumns);
            } else if (this.user_department_type == 1) {
              // 集团公司高层可查看全部停车场
              for (let i in res.data) {
                let dump = {
                  id: res.data[i].id,
                  name: res.data[i].areaname,
                  parent_id: res.data[i].project_company_id,
                  area_coordinates: null,
                  overlay: null
                };
                if (typeof res.data[i].area == "string") {
                  dump.area_coordinates = JSON.parse(res.data[i].area);
                }
                this.dump_info.push(dump);
                this.showAndSaveFence(dump, "dump");
              }
            }
            // var result = this.dump_info.map(o => {
            //   return {
            //     text: o.name,
            //     value: o.id
            //   };
            // });
            // result.unshift({ text: "请选择项目公司回收站", value: 0 });
            // this.ProjectCompanyDumpcolumns = result;
            // console.log("请选择项目公司回收站", this.ProjectCompanyDumpcolumns);
          } else {
            this.$toast({ message: res.msg });
          }
        });
    },
    //获取垃圾桶
    getTrash() {
      var params = {
        token: this.token
      };
      this.$http
        .get(`${this.$basePath}?service=App.Device.GetDeviceList&api=83`, {
          params: params
        })
        .then(res => {
          if (res.ret == 200) {
            console.log("垃圾桶列表", res);
            if (
              this.user_department_type == 3 ||
              this.user_department_type == 5
            ) {
              // 项目公司部经理只能查看自己项目部的垃圾桶
              // 项目公司经理只能查看自己公司的垃圾桶
              for (let i in res.data) {
                var project_info = this.project_info;
                for (let j in project_info) {
                  if (project_info[j].id == res.data[i].project_id) {
                    let trash = {
                      id: res.data[i].id,
                      name: res.data[i].name,
                      parent_id: res.data[i].project_id,
                      pparent_id: project_info[j].parent_id,
                      photo: res.data[i].photo,
                      coordinates: null,
                      overlay: null,
                      markerShow: true
                    };
                    let coordinates = null;
                    if (typeof res.data[i].workplace == "string") {
                      coordinates = JSON.parse(res.data[i].workplace);
                    }
                    trash.coordinates = {
                      lng: coordinates.lon,
                      lat: coordinates.lat
                    };
                    this.trash_info.push(trash);
                    console.log("垃圾桶", this.trash_info);

                    this.showAndSaveMarker(trash, "trash");
                  }
                }
              }
              var result = this.trash_info.map(o => {
                return {
                  text: o.name,
                  value: o.id
                };
              });
              result.unshift({ text: "选择垃圾桶", value: 0 });
              this.ProjectTrashcolumns = result;
              console.log("选择垃圾桶", this.ProjectTrashcolumns);
            } else if (this.user_department_type == 1) {
              // 集团公司高层可查看全部垃圾桶
              for (let i in res.data) {
                let trash = {
                  id: res.data[i].id,
                  name: res.data[i].name,
                  parent_id: res.data[i].project_id,
                  photo: res.data[i].photo,
                  coordinates: null,
                  overlay: null,
                  markerShow: true
                };
                var project_info = this.project_info;
                for (let j in project_info) {
                  if (project_info[j].id == trash.parent_id) {
                    trash.pparent_id = project_info[j].parent_id;
                    break;
                  }
                }
                let coordinates = null;
                if (typeof res.data[i].workplace == "string") {
                  coordinates = JSON.parse(res.data[i].workplace);
                }
                trash.coordinates = {
                  lng: coordinates.lon,
                  lat: coordinates.lat
                };
                this.trash_info.push(trash);
                console.log("垃圾桶", this.trash_info);
                this.showAndSaveMarker(trash, "trash");
              }
              // var result = this.trash_info.map(o => {
              //   return {
              //     text: o.name,
              //     value: o.id
              //   };
              // });
              // result.unshift({ text: "请选择项目部垃圾桶", value: 0 });
              // this.ProjectTrashcolumns = result;
              // console.log("请选择项目部垃圾桶", this.ProjectTrashcolumns);
            }
          } else {
            this.$toast({ message: res.msg });
          }
        });
    },

    //筛选围栏
    showOrHideone(type, id) {
      var object = null;

      switch (type) {
        case "company":
          object = this.company_info;

          break;
        case "project":
          object = this.project_info;

          break;
        case "district":
          object = this.district_info;

          break;
        case "user":
          object = this.user_info;

          break;
        case "car":
          object = this.car_info;
          break;
        case "park":
          object = this.park_info;
          break;
      }
      console.info("操作pianqu对象", id, type, object);
      //隐藏所有片区
      for (let i in object) {
        if (object[i].overlay) {
          object[i].overlay.hide();
        }
      }
      //匹配选中的id
      var obj = object.find(function(obj) {
        return obj.id == id;
      });
      //console.log(obj);
      if (obj.overlay != null) {
        obj.overlay.show();
      } else {
        this.$toast({ message: "没有相关数据" });
      }
    },
    //筛选保洁员和车辆
    showOrHideCarAndUserone(type, id, target) {
      var object = null;
      switch (type) {
        case "user":
          object = this.user_info;
          for (let i in object) {
            if (object[i].marker) {
              object[i].marker.hide();
            }
          }
          //console.log("user");
          var newarr = [];
          for (let i in object) {
            if (object[i].department_id == id) {
              newarr.push(object[i]);
            }
          }
          //console.log("当前片区", newarr);
          for (let i in newarr) {
            if (newarr[i].marker) {
              newarr[i].marker.show();
            }
          }
          break;
        case "car":
          //console.log("car");
          object = this.car_info;
          for (let i in object) {
            if (object[i].marker) {
              object[i].marker.show();
            }
          }
          break;
      }
      console.info("操作usercar对象", id, type, object);
    },
    /*项目部*/
    //选择项目公司

    onConfirmProjectCompany() {
      console.log("选项目公司");
      //显示当前围栏

      this.ProjectTrash = 0;
      this.ProjectTrashcolumns = [{ text: "选择项垃圾桶", value: 0 }];
      this.ProjectCar = 0;
      this.ProjectCarcolumns = [{ text: "选择车辆", value: 0 }];
      this.District = 0;
      this.DutyArea = 0;
      this.Districtcolumns = [{ text: "选择项目片区", value: 0 }];
      this.DutyAreacolumns = [{ text: "选择项责任区", value: 0 }];
      this.Project = 0;
      this.Projectcolumns = [{ text: "选择项目部", value: 0 }];
      this.ProjectCompanyPark = 0;
      this.ProjectCompanyParkcolumns = [{ text: "选择停车场", value: 0 }];
      this.ProjectCompanyDump = 0;
      this.ProjectCompanyDumpcolumns = [{ text: "选择回收站", value: 0 }];

      //移到围栏中心点
      if (this.ProjectCompany != 0) {
        this.activeThis("company", this.ProjectCompany);
        //加载项目部slelct

        for (let i in this.project_info) {
          if (this.project_info[i].parent_id == this.ProjectCompany) {
            this.Projectcolumns.push(this.project_info[i]);
          }
        }
        if (this.Projectcolumns.length > 0) {
          this.Projectcolumns.shift();
          var obj = this.Projectcolumns;
          var result = obj.map(o => {
            return {
              text: o.name,
              value: o.id
            };
          });
          result.unshift({ text: "选择项目部", value: 0 });
          this.Projectcolumns = result;
        }
        //加载项目公司停车场select

        for (let i in this.park_info) {
          if (this.park_info[i].parent_id == this.ProjectCompany) {
            this.ProjectCompanyParkcolumns.push(this.park_info[i]);
          }
        }
        if (this.ProjectCompanyParkcolumns.length > 0) {
          this.ProjectCompanyParkcolumns.shift();
          var obj = this.ProjectCompanyParkcolumns;
          var result = obj.map(o => {
            return {
              text: o.name,
              value: o.id
            };
          });
          result.unshift({ text: "选择停车场", value: 0 });
          this.ProjectCompanyParkcolumns = result;
        }
        //加载项目公司回收站select

        for (let i in this.dump_info) {
          if (this.dump_info[i].parent_id == this.ProjectCompany) {
            this.ProjectCompanyDumpcolumns.push(this.dump_info[i]);
          }
        }
        if (this.ProjectCompanyDumpcolumns.length > 0) {
          this.ProjectCompanyDumpcolumns.shift();
          var obj = this.ProjectCompanyDumpcolumns;
          var result = obj.map(o => {
            return {
              text: o.name,
              value: o.id
            };
          });
          result.unshift({ text: "选择回收站", value: 0 });
          this.ProjectCompanyDumpcolumns = result;
        }
      }
    },
    //项目公司停车场
    onConfirmProjectCompanyPark() {
      if (this.ProjectCompanyPark != 0) {
        this.activeThis("park", this.ProjectCompanyPark);
      }
    },
    //项目公司回收站
    onConfirmProjectCompanyDump() {
      if (this.ProjectCompanyDump != 0) {
        this.activeThis("dump", this.ProjectCompanyDump);
      }
    },
    //项目部垃圾桶
    onConfirmProjectTrash() {
      if (this.ProjectTrash != 0) {
        this.activeThis("trash", this.ProjectTrash);
      }
    },
    //项目部车辆
    onConfirmProjectCar() {
      if (this.ProjectCar != 0) {
        this.activeThis("car", this.ProjectCar);
      }
    },
    //选择项目部

    onConfirmProject() {
      this.projectcardisplay = true;
      this.projecttrashdisplay = true;
      this.dirstdisplay = true;
      this.dutydisplay = true;
      console.log("选项目部");
      this.District = 0;
      this.Districtcolumns = [{ text: "选择项目片区", value: 0 }];
      this.ProjectTrash = 0;
      this.ProjectTrashcolumns = [{ text: "选择垃圾桶", value: 0 }];
      this.ProjectCar = 0;
      this.ProjectCarcolumns = [{ text: "选择车辆", value: 0 }];

      if (this.Project != 0) {
        this.activeThis("project", this.Project);
        //加载项目部垃圾桶slelct
        for (let i in this.trash_info) {
          if (this.trash_info[i].parent_id == this.Project) {
            this.ProjectTrashcolumns.push(this.trash_info[i]);
          }
        }

        if (this.ProjectTrashcolumns.length > 0) {
          this.ProjectTrashcolumns.shift();
          var obj = this.ProjectTrashcolumns;
          console.log(111, obj);
          var result = obj.map(o => {
            return {
              text: o.name,
              value: o.id
            };
          });
          result.unshift({ text: "选择垃圾桶", value: 0 });
          this.ProjectTrashcolumns = result;
        }

        //加载项目部车辆select
        for (let i in this.car_info) {
          if (this.car_info[i].department_id == this.Project) {
            this.ProjectCarcolumns.push(this.car_info[i]);
          }
        }

        if (this.ProjectCarcolumns.length > 0) {
          this.ProjectCarcolumns.shift();
          var obj = this.ProjectCarcolumns;
          console.log(111, obj);
          var result = obj.map(o => {
            return {
              text: o.name,
              value: o.id
            };
          });
          result.unshift({ text: "选择车辆", value: 0 });
          this.ProjectCarcolumns = result;
        }

        //加载项目部片区select

        for (let i in this.district_info) {
          if (this.district_info[i].parent_id == this.Project) {
            this.Districtcolumns.push(this.district_info[i]);
          }
        }

        if (this.Districtcolumns.length > 0) {
          this.Districtcolumns.shift();
          var obj = this.Districtcolumns;
          console.log(111, obj);
          var result = obj.map(o => {
            return {
              text: o.name,
              value: o.id
            };
          });
          result.unshift({ text: "选择项目部片区", value: 0 });
          this.Districtcolumns = result;
        }
      }
    },
    //选择片区

    onConfirmDistrict() {
      this.DutyArea = 0;
      this.DutyAreacolumns = [{ text: "选择责任区", value: 0 }];

      //加载项目责任区slelct

      if (this.District != 0) {
        this.activeThis("district", this.District);
        for (let i in this.user_info) {
          if (this.user_info[i].department_id == this.District) {
            this.DutyAreacolumns.push(this.user_info[i]);
          }
        }

        if (this.DutyAreacolumns.length > 0) {
          this.DutyAreacolumns.shift();
          var obj = this.DutyAreacolumns;
          console.log(111, obj);
          var result = obj.map(o => {
            return {
              text: o.name,
              value: o.id
            };
          });
          result.unshift({ text: "选择责任区", value: 0 });
          this.DutyAreacolumns = result;
        }
      }
    },
    //选择责任区
    onConfirmDutyArea() {
      //显示当前围栏
      if (this.DutyArea != 0) {
        this.activeThis("person", this.DutyArea);
      }
    },

    /**筛选条件 */
    // 时间戳转年月日时分秒
    add0(m) {
      return m < 10 ? "0" + m : m;
    },
    timeFormat(ts) {
      var that = this;
      var result = "";
      if (typeof ts === "number") {
        switch (ts.toString().length) {
          case 10:
            ts = ts * 1000;
            var time = new Date(ts);
            var y = time.getFullYear();
            var m = time.getMonth() + 1;
            var d = time.getDate();
            var h = time.getHours();
            var mm = time.getMinutes();
            var s = time.getSeconds();
            return (
              y +
              "-" +
              that.add0(m) +
              "-" +
              that.add0(d) +
              " " +
              that.add0(h) +
              ":" +
              that.add0(mm) +
              ":" +
              that.add0(s)
            );
          case 13:
            var time = new Date(ts);
            var y = time.getFullYear();
            var m = time.getMonth() + 1;
            var d = time.getDate();
            var h = time.getHours();
            var mm = time.getMinutes();
            var s = time.getSeconds();
            return (
              y +
              "-" +
              that.add0(m) +
              "-" +
              that.add0(d) +
              " " +
              that.add0(h) +
              ":" +
              that.add0(mm) +
              ":" +
              that.add0(s)
            );
            break;
        }
      }
    },
    /**
     * 报警信息
     */

    /**
     * 展开搜索 */
    ela() {
      this.ellipsis = !this.ellipsis;
      this.titleshow = !this.titleshow;
    },
    elatitle() {
      this.ellipsis = !this.ellipsis;
      this.titleshow = !this.titleshow;
    },
    tuceng() {
      this.tcellipsis = !this.tcellipsis;
      this.tctitleshow = !this.tctitleshow;
    },
    tcelatitle() {
      this.tcellipsis = !this.tcellipsis;
      this.tctitleshow = !this.tctitleshow;
    },
    bgeal() {
      this.bgellipsis1 = !this.bgellipsis1;
      this.bgtitleshow = !this.bgtitleshow;
    },
    bgtitle() {
      this.bgellipsis1 = !this.bgellipsis1;
      this.bgtitleshow = !this.bgtitleshow;
    },
    topela() {
      this.topellipsis = !this.topellipsis;
      this.toptitleshow = !this.toptitleshow;
    },
    topelatitle() {
      this.topellipsis = !this.topellipsis;
      this.toptitleshow = !this.toptitleshow;
    }
  },
  destroy() {
    window.clearInterval(this.interval);
    window.clearInterval(this.interval1);
  }
};
</script>

<style lang="less" scoped>
@import "../../assets/css/mointer";
.table1 {
  font-size: 10px !important;
}
.historybut {
  background: #fff !important;
  outline: none;
  border: 1px solid #eee;
}
.uldemo {
  min-height: 100px;
  max-height: 100px;
  overflow: scroll;
  background: rgba(0, 0, 0, 0.55);
}
.color1 {
  color: #2ec055 !important;
}
.color2 {
  color: #8a70f7 !important;
}
.color3 {
  color: #ff5065 !important;
}
.color4 {
  color: #01a7eb !important;
}

.labelcircle {
  width: 10px;
  height: 10px;
  border-radius: 100%;
  display: inline-block;
}
.company {
  background: #e60012;
}
.project {
  background: #8957a1;
}
.district {
  background: #ff5065;
}
.user {
  background: #40a000;
}
.car {
  background: #ff6600;
}
.park {
  background: #516ca6;
}
.dump {
  background: #00a0e9;
}
</style>
